<?php

// Database Settings
$database = "";
$sqlhost = "";
$sqluser = "";
$sqlpass = "";

$connection = mysql_connect($sqlhost, $sqluser, $sqlpass);
if (! $connection) die ("Connection error");
mysql_select_db($database) or die ("Can't open database: ".mysql_error());

$charname = $HTTP_POST_VARS[site];
$charname = $HTTP_POST_VARS[charname];
$time = time();

$search = mysql_query("SELECT vote FROM characters WHERE char_name='$charname'");
while($someone = mysql_fetch_array($search))
{
	$lastvote = $someone[vote];
}

if ($lastvote == '')
{
	mysql_query ("UPDATE characters SET vote = $time WHERE char_name = $charname"); 
	header("Location: $site");
	exit();   
}
else
{
	$difference = round(abs($time-$lastvote) / 360);

	if ($difference >= 12)
	{
		mysql_query ("UPDATE characters SET vote = $time WHERE char_name = $charname");
		header("Location: $site");
		exit();  
	}
	else
	{
		$error = "You have to wait $difference hours to vote again";
		header("Location:index.php?error=$error");
		exit();
	}
}

?>